import './App.less';
import React from "react";
import {useRoutes} from "react-router-dom";
import {routerList} from "./router/index";
import store from "./store";
import {user} from "./request";
import {USER_LOGIN} from "./store/actionTypes";




function App(){
    const [token1,setToken1] = React.useState(localStorage.getItem('token'))
    React.useEffect(()=>{
        if (store.getState().user.user_id === undefined){
            if (token1 !== null)
            mySigIn()
        }
    })
    const mySigIn = async()=>{
            const {data:res} = await user.getUser(await localStorage.getItem('token'))
            const action = {
                type:USER_LOGIN,
                UserInformation:res.data[0]
            }
            store.dispatch(action)
    }
    const element = useRoutes(routerList)
    return (
        <div className="App" style={{display:"flex"}}>
            {element}
        </div>
    );
}

export default App;
